Skip to content

platform: use FILE_FLAG_WRITE_THROUGH on Windows for SyncFile data durability, fixes #9388#9389

Open
mr-raj12 wants to merge 1 commit intoborgbackup:masterfrom
mr-raj12:win32-syncfile-write-through
Open

platform: use FILE_FLAG_WRITE_THROUGH on Windows for SyncFile data durability, fixes #9388#9389
mr-raj12 wants to merge 1 commit intoborgbackup:masterfrom
mr-raj12:win32-syncfile-write-through

Conversation

@mr-raj12
Copy link
Contributor

Description

Implement Windows-native SyncFile using CreateFileW with FILE_FLAG_WRITE_THROUGH to bypass volatile write caches and write directly to persistent storage. This is the Windows equivalent of the macOS F_FULLFSYNC fix (#9383 / PR #9385).

Fixes #9388

Changes

  • src/borg/platform/windows.pyx — add SyncFile subclass using CreateFileW + FILE_FLAG_WRITE_THROUGH; falls back to base when an existing fd is provided (e.g. SaveFile)
  • src/borg/platform/__init__.py — import SyncFile from .windows instead of .base
  • src/borg/platform/base.py — update resolved TODO comment
  • src/borg/testsuite/platform/platform_test.py — add skipif_not_win32 marker
  • src/borg/testsuite/platform/windows_test.py — 6 tests (write/read, FileExistsError, text mode, fd fallback, sync, write-through flag verification)

Checklist

  • PR is against master (or maintenance branch if only applicable there)
  • New code has tests and docs where appropriate
  • Tests pass (run tox or the relevant test subset)
  • Commit messages are clean and reference related issues

@codecov
Copy link

codecov bot commented Feb 21, 2026

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
1681 1 1680 346
View the top 1 failed test(s) by shortest run time
::src.borg.testsuite.platform.windows_test
Stack Traces | 0s run time
ImportError while importing test module '.../testsuite/platform/windows_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
.../hostedtoolcache/Python/3.14.3.../x64/lib/python3.14/importlib/__init__.py:88: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.../testsuite/platform/windows_test.py:7: in <module>
    from ...platform import windows
E   ImportError: cannot import name 'windows' from 'borg.platform' (.../borg/platform/__init__.py)

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Copy link
Member

@ThomasWaldmann ThomasWaldmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor things i found

@ThomasWaldmann
Copy link
Member

Also:

Please update your local master branch and then rebase this branch onto that master and force push.

That should solve the CI test failures that are unrelated to your work.

Copy link
Member

@ThomasWaldmann ThomasWaldmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one idea about reducing these in-function imports.

i am not familiar with the windows api, did you check yourself that this win32 api usage is how it should be?

@ThomasWaldmann ThomasWaldmann added this to the 2.0.0b21 milestone Feb 28, 2026
@mr-raj12 mr-raj12 force-pushed the win32-syncfile-write-through branch from 5df3cfb to fcbd613 Compare March 1, 2026 10:24
@mr-raj12
Copy link
Contributor Author

mr-raj12 commented Mar 1, 2026

one idea about reducing these in-function imports.

i am not familiar with the windows api, did you check yourself that this win32 api usage is how it should be?

Yes cross checked everything against the CreateFileW and _open_osfhandle docs

@ThomasWaldmann
Copy link
Member

from ...platform import windows

SyncFile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

platform: implement Windows-native SyncFile using FILE_FLAG_WRITE_THROUGH

2 participants